package com.focus.wecenter.pojo;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.Date;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * @description
 * 
 * @author		Lv Jing
 * @date		2018-1-6 10:36:28
 */
@Entity
@Table(name = "user", schema = "wecenter")
@DynamicInsert
@DynamicUpdate
public class User implements Serializable {
	private static final long serialVersionUID = 1L;

	private Integer id;
	/**用户登录账号*/
	private String username;
	/**登录密码，用md5再加盐进行加密*/
	private String password;
	/**邮箱*/
	private String email;
	/**一句话介绍*/
	private String introduction;
	/**用户头像*/
	private String headPortrait;
	/**1：男  2：女  3：保密*/
	private Byte sex;
	/**加密混淆*/
	private String salt;
	/**生日*/
	private Integer birthday;
	/**所在省*/
	private String province;
	/**所在市*/
	private String city;
	/**职业*/
	private String job;
	/**粉丝数*/
	private Integer fansCount;
	/**关注数*/
	private Integer concernCount;
	/**文章数量*/
	private Integer articleCount;
	/**问题数量*/
	private Integer questionCount;
	/**回答数量*/
	private Integer answerCount;
	/**关注话题数量*/
	private Integer topicFocusCount;
	/**赞同数量*/
	private Integer agreeCount;
	/**积分*/
	private Integer integral;
	/**创建时间*/
	private Date createTime;
	/**修改时间*/
	private Date updateTime;
    /**创建的问题*/
	private Set<Question> createdQuestions = new HashSet<>(0);
	/**创建的文章*/
	private Set<Article> createArticles = new HashSet<>(0);
    /**用户关注问题*/
	private Set<Question> focusQuestions = new HashSet<>(0);
	/**用户关注话题*/
	private Set<Topic> focusTopics = new HashSet<>(0);
	/**关注的用户*/
	private Set<User> focusUsers = new HashSet<>(0);
	/**粉他的用户*/
	private Set<User> fansUsers = new HashSet<>(0);

    @JoinTable(name = "user_focus", joinColumns = {@JoinColumn(name = "fans_id")}, inverseJoinColumns = {@JoinColumn(name = "concern_id")})
    @ManyToMany
    public Set<User> getFocusUsers() {
        return focusUsers;
    }
    public void setFocusUsers(Set<User> focusUsers) {
        this.focusUsers = focusUsers;
    }
    @JoinTable(name = "user_focus", joinColumns = {@JoinColumn(name = "concern_id")}, inverseJoinColumns = {@JoinColumn(name = "fans_id")})
    @ManyToMany
    public Set<User> getFansUsers() {
        return fansUsers;
    }
    public void setFansUsers(Set<User> fansUsers) {
        this.fansUsers = fansUsers;
    }
    @JoinColumn(name = "user_id")
	@OneToMany
	@OrderBy("createTime desc")
	public Set<Article> getCreateArticles() {
		return createArticles;
	}
	public void setCreateArticles(Set<Article> createArticles) {
		this.createArticles = createArticles;
	}
	@JoinTable(name = "topic_focus", joinColumns = {@JoinColumn(name = "user_id")}, inverseJoinColumns = {@JoinColumn(name = "topic_id")})
    @ManyToMany
    @OrderBy("createTime desc")
    public Set<Topic> getFocusTopics() {
        return focusTopics;
    }
    public void setFocusTopics(Set<Topic> focusTopics) {
        this.focusTopics = focusTopics;
    }
    @JoinTable(name = "question_focus", joinColumns = {@JoinColumn(name = "user_id")}, inverseJoinColumns = {@JoinColumn(name = "question_id")})
	@ManyToMany
    @OrderBy("createTime desc")
    public Set<Question> getFocusQuestions() {
        return focusQuestions;
    }
    public void setFocusQuestions(Set<Question> focusQuestions) {
        this.focusQuestions = focusQuestions;
    }
    /**
     * 注解实现一对多，使用OneToMany，JoinColumn指定外键
     */
    @JoinColumn(name = "user_id")
    @OneToMany
    @OrderBy("createTime desc")
    public Set<Question> getCreatedQuestions() {
        return createdQuestions;
    }
    public void setCreatedQuestions(Set<Question> createdQuestions) {
        this.createdQuestions = createdQuestions;
    }
    @Id
    @Column(name = "USER_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Basic
    @Column(name = "USERNAME")
	public String getUsername() {
		return this.username;
	}
	public void setUsername(String username) {
		this.username = username;
	}	
	@Basic
    @Column(name = "PASSWORD")
	public String getPassword() {
		return this.password;
	}
	public void setPassword(String password) {
		this.password = password;
	}	
	@Basic
    @Column(name = "EMAIL")
	public String getEmail() {
		return this.email;
	}
	public void setEmail(String email) {
		this.email = email;
	}	
	@Basic
    @Column(name = "INTRODUCTION")
	public String getIntroduction() {
		return this.introduction;
	}
	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}	
	@Basic
    @Column(name = "HEAD_PORTRAIT")
	public String getHeadPortrait() {
		return this.headPortrait;
	}
	public void setHeadPortrait(String headPortrait) {
		this.headPortrait = headPortrait;
	}	
	@Basic
    @Column(name = "SEX")
	public Byte getSex() {
		return this.sex;
	}
	public void setSex(Byte sex) {
		this.sex = sex;
	}	
	@Basic
    @Column(name = "SALT")
	public String getSalt() {
		return this.salt;
	}
	public void setSalt(String salt) {
		this.salt = salt;
	}	
	@Basic
    @Column(name = "BIRTHDAY")
	public Integer getBirthday() {
		return this.birthday;
	}
	public void setBirthday(Integer birthday) {
		this.birthday = birthday;
	}	
	@Basic
    @Column(name = "PROVINCE")
	public String getProvince() {
		return this.province;
	}
	public void setProvince(String province) {
		this.province = province;
	}	
	@Basic
    @Column(name = "CITY")
	public String getCity() {
		return this.city;
	}
	public void setCity(String city) {
		this.city = city;
	}	
	@Basic
    @Column(name = "JOB")
	public String getJob() {
		return this.job;
	}
	public void setJob(String job) {
		this.job = job;
	}	
	@Basic
    @Column(name = "FANS_COUNT")
	public Integer getFansCount() {
		return this.fansCount;
	}
	public void setFansCount(Integer fansCount) {
		this.fansCount = fansCount;
	}	
	@Basic
    @Column(name = "CONCERN_COUNT")
	public Integer getConcernCount() {
		return this.concernCount;
	}
	public void setConcernCount(Integer concernCount) {
		this.concernCount = concernCount;
	}	
	@Basic
    @Column(name = "ARTICLE_COUNT")
	public Integer getArticleCount() {
		return this.articleCount;
	}
	public void setArticleCount(Integer articleCount) {
		this.articleCount = articleCount;
	}	
	@Basic
    @Column(name = "QUESTION_COUNT")
	public Integer getQuestionCount() {
		return this.questionCount;
	}
	public void setQuestionCount(Integer questionCount) {
		this.questionCount = questionCount;
	}	
	@Basic
    @Column(name = "ANSWER_COUNT")
	public Integer getAnswerCount() {
		return this.answerCount;
	}
	public void setAnswerCount(Integer answerCount) {
		this.answerCount = answerCount;
	}	
	@Basic
    @Column(name = "TOPIC_FOCUS_COUNT")
	public Integer getTopicFocusCount() {
		return this.topicFocusCount;
	}
	public void setTopicFocusCount(Integer topicFocusCount) {
		this.topicFocusCount = topicFocusCount;
	}	
	@Basic
    @Column(name = "AGREE_COUNT")
	public Integer getAgreeCount() {
		return this.agreeCount;
	}
	public void setAgreeCount(Integer agreeCount) {
		this.agreeCount = agreeCount;
	}	
	@Basic
    @Column(name = "INTEGRAL")
	public Integer getIntegral() {
		return this.integral;
	}
	public void setIntegral(Integer integral) {
		this.integral = integral;
	}	
	@Basic
    @Column(name = "CREATE_TIME")
	public Date getCreateTime() {
		return this.createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}	
	@Basic
    @Column(name = "UPDATE_TIME")
	public Date getUpdateTime() {
		return this.updateTime;
	}
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        User user = (User) o;
        return id.equals(user.id);
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }
}